找传奇、传世资源到传世资源站!

android_ebup电子书阅读_例子源码_

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

android_ebup电子书阅读_例子源码_ Android平台开发-第1张

package com.lj.filenamager;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.lj.filenamager.util.ClearEditText;
import com.lj.filenamager.util.GetImgName;
import com.lj.filenamager.util.MyAdspter;
import com.lj.filenamager.util.sql.DBHelper;
import com.lj.filenamager.util.sql.DBManager;
import com.lj.filenamager.util.tree.Bean;
import com.lj.filenamager.util.tree.FileBean;
import com.lj.filenamager.util.tree.TreeListViewAdapter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {
	private List<Bean> mDatas = new ArrayList<Bean>();
	private List<FileBean> mDatas2 = new ArrayList<FileBean>();
	private ListView mTree;
	private TreeListViewAdapter<FileBean> mAdapter;
	private String infopath;
	private int fi = 0;
	private int i = 0;
	private ListView listView = null;
	List<Map<String, Object>> list = null;
	EditText editText = null;
	DBHelper dbHelper = null;
	DBManager dbManager=null;
	private SQLiteDatabase database;
	private ClearEditText inputsearch;
	public Handler mHandler = null;
	public List<Map<String, Object>> searchList = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) { 
		super.onCreate(savedInstanceState);

		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_main);
		listView = (ListView) findViewById(R.id.id_tree);
		editText = (EditText) findViewById(R.id.inputsearch);
		MyApplication myapplicaton = (MyApplication) getApplication();
		list = getData(((MyApplication) getApplication()).getInfopath());
		listView.setAdapter(new MyAdspter(this, list));
		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				String name = list.get(arg2).get("title").toString();
				String end = name.substring(name.lastIndexOf(".")  1,
						name.length()).toLowerCase();
				if (end.equals("epub")) {
					Intent intent = new Intent();
					intent.setClass(MainActivity.this, EputActivity2.class);
					Bundle bundle = new Bundle();
					bundle.putString("pathfile",
							((MyApplication) getApplication()).getInfopath()
									 name);
					intent.putExtras(bundle);
					startActivity(intent);
				} else if (end.equals("doc")) {
					Intent intent = new Intent();
					intent.setClass(MainActivity.this, InformationScanViewFile.class);
				} else if(name.indexOf(".")==-1){
					((MyApplication) getApplication())
							.setInfopath(((MyApplication) getApplication())
									.getInfopath()  name  "/");
					((MyApplication) getApplication()).setFilepath(name  "/");
					Intent intent = new Intent();
					intent.setClass(MainActivity.this, MainActivity2.class);
					startActivity(intent);
				}else{
					
				}
			}
		});
		dbHelper = new DBHelper(this);
		mHandler = new Handler() {
			public void handleMesage(Message msg) {
				switch (msg.what) {
				case 1:
					editText.setFocusable(true);
					editText.setEnabled(true);
					break;
				case 2:
					listView.setAdapter(new MyAdspter(MainActivity.this, list));
					// 取回Adapter对象,用于调用notifyDataSetChanged方法。
					MyAdspter sAdapter = (MyAdspter) listView.getAdapter();
					sAdapter.notifyDataSetChanged();
					break;
				default:
					break;
				}
				super.handleMessage(msg);
			}
		};
		startThreadForData();
		searInputChangeListener();
	}

	/**
	 * 输入框搜索事件
	 */

	public void searInputChangeListener() {
		inputsearch = (ClearEditText) this.findViewById(R.id.inputsearch);
		inputsearch.addTextChangedListener(new TextWatcher() {
			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				// 当输入框里面的值为空,更新为原来的列表,否则为过滤数据列表
				if (s != null && !"".equals(s.toString())) {
					Intent intent = new Intent();
					intent.setClass(MainActivity.this, SearchActivity.class);
					Bundle bundle = new Bundle();
					bundle.putString("filename", s.toString());
					intent.putExtras(bundle);
					startActivity(intent);
				} else {
//					System.out.println("输入框为空");
				}

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
			}
		});
	}

	public void startThreadForData() {
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					dbHelper.createDataBase();
					dbHelper.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
				Message message = new Message();
				message.what = 1;
				mHandler.sendMessage(message);
			}
		}).start();
	}

	public List<Map<String, Object>> getData(String infopath) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		File file = new File(infopath);
		File[] files = file.listFiles();
		if (files != null && files.length > 0) {
			for (File f : files) {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("title", f.getName());
				String imgName=GetImgName.getPropertiesURL(MainActivity.this, f.getName());
				if(imgName!=""){
					map.put("image", GetImgName.getImageResourceId(imgName));
				}else{
					map.put("image", R.drawable.p34);
				}
				list.add(map);
			}
		} else {
			Toast toast = Toast.makeText(MainActivity.this, "没有找到文件",
					Toast.LENGTH_SHORT);
			toast.show();
		}
		return list;
	}

}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复